<template>
  <div>
    <h4>修改信息</h4>
    <el-form ref="form" label-width="80px">
      <el-form-item label="店铺名称">
        <el-input
          v-model="shopData.name"
          minlength="3"
          maxlength="12"
          :show-word-limit="true"
          size="small"
          style="width:240px"
        ></el-input>
      </el-form-item>
      <el-form-item label="店铺简介">
        <el-input
          type="textarea"
          v-model="shopData.desc"
          maxlength="200"
          :show-word-limit="true"
          style="width:500px"
        ></el-input>
      </el-form-item>
      <el-form-item label="店铺类型">
        <el-radio-group v-model="shopData.Type">
          <el-radio label="个人店铺"></el-radio>
          <el-radio label="企业店铺"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="店铺地址">
        <el-radio-group v-model="shopData.address">
          <el-radio label="大陆"></el-radio>
          <el-radio label="香港"></el-radio>
          <el-radio label="台湾"></el-radio>
          <el-radio label="海外"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="注册资金">
        <el-input
          v-model="shopData.registerMoney"
          maxlength="10"
          :show-word-limit="true"
          size="small"
          style="width:140px"
        ></el-input>元
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即修改</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("shop");
export default {
  data() {
    return {
      shop: {
        name: "",
        merchantName: "",
        desc: "",
        type: "",
        adress: "",
        registermoney: "",
        state: 1
      },
      merchant: "",
      shopData: {}
    };
  },
  methods: {
    ...mapActions(["getMerchantAsync", "updateShopAsync"]),
    async onSubmit() {
      let { data } = await this.updateShopAsync(this.shopData);
      if (data) {
        this.$alert("修改成功", "修改", {
          confirmButtonText: "确定",
          callback: action => {
            this.$router.push('/merchant/MerchantRead');
          }
        });
      }
    }
  },
  created() {
    this.merchant = sessionStorage.getItem("userName");
  },
  watch: {
    async merchant() {
      this.shopData = await this.getMerchantAsync(this.merchant);
    }
  }
};
</script>

<style>
</style>